from datetime import datetime
from typing import Union

from pydantic import BaseModel


class InterestBase(BaseModel):
    user_id: int
    is_viper: int
    points: int
    free_count: int
    status: int


class InterestCreate(InterestBase):
    pass


class Interest(InterestBase):
    id: int
    user_id: int

    class Config:
        from_attributes = True


class UserBase(BaseModel):
    nick_name: Union[str, None] = None
    avatar: Union[str, None] = None
    wx_open_id: str
    wx_union_id: Union[str, None] = None
    wx_session_key: str
    wx_js_code: str
    invite_code: Union[str, None] = None
    up_time: int


class UserCreate(UserBase):
    wx_js_code: str
    wx_open_id: str
    wx_session_key: str


class UserUpdate(UserBase):
    id: int
    wx_open_id: str
    wx_union_id: str
    wx_session_key: str
    js_code: str
    up_time: int


class User(UserBase):
    id: int
    interests: Interest

    class Config:
        from_attributes = True


class InvitationBase(BaseModel):
    pass


class InvitationCreate(InvitationBase):
    inviter_id: int
    invitee_id: int
    status: int
    created_at: datetime = datetime.now()
    updated_at: datetime = datetime.now()


class InvitationUpdate(InvitationBase):
    status: int
    updated_at: datetime = datetime.now()


class Invitation(InvitationBase):
    id: int

    class Config:
        from_attributes = True


class OrderBase(BaseModel):
    user_id: int
    pic: str
    out_pic: str = None
    type: int
    size: str = None
    pixel: str
    status: int
    created_at: datetime = datetime.now()
    updated_at: datetime = datetime.now()


class OrderCreate(OrderBase):
    pass


class OrderUpdate(OrderBase):
    pic: str
    out_pic: str
    status: int


class Order(OrderBase):
    id: int

    class Config:
        from_attributes = True
